﻿using System;

namespace Tiscs.Practices.Diagnostics
{
    /// <summary>
    /// 参数验证规则。
    /// </summary>
    /// <typeparam name="T">要验证的参数的类型。</typeparam>
    internal class ParameterRule<T>
    {
        /// <summary>
        /// 构造方法。
        /// </summary>
        /// <param name="predicate">参数验证方法。</param>
        /// <param name="exceptionCreator">创建异常信息的方法。</param>
        public ParameterRule(Func<T, bool> predicate, Func<string, Exception> exceptionCreator)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }
            if (exceptionCreator == null)
            {
                throw new ArgumentNullException(nameof(exceptionCreator));
            }
            Predicate = predicate;
            ExceptionCreator = exceptionCreator;
        }

        /// <summary>
        /// 参数验证方法。
        /// </summary>
        internal Func<T, bool> Predicate { get; private set; }

        /// <summary>
        /// 创建异常信息的方法。
        /// </summary>
        internal Func<string, Exception> ExceptionCreator { get; private set; }
    }
}
